﻿/*
 * Created by SharpDevelop.
 * User: wanggy
 * Date: 2009/10/21
 * Time: 17:41
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;

namespace XRunner.SDK.XUtill
{
	/// <summary>
	/// Description of reportUtil.
	/// </summary>
	public class reportUtil
	{
		private reportUtil()
		{
		}
		/// <summary>
		/// 用来填充一个listview空间的共同方法
		/// </summary>
		/// <param name="dt">数据表</param>
		/// <param name="lv">listview对象</param>
		/// <param name="titles">一个映射数据格式和现实内容的映射，可以用作过滤功能</param>
		public static void createReportView(DataTable dt, ListView lv, Hashtable titles)
		{

			lv.Clear();
			List<string> keyList = new List<string>();
			foreach(DataColumn dc in dt.Columns)
			{
				string titleKey = dc.ColumnName;
				if (titles != null)
				{
					if(titles.ContainsKey(titleKey))
					{
						lv.Columns.Add(titles[titleKey].ToString());
					} else
					{
						continue;
					}
				} else
				{
					lv.Columns.Add(titleKey);
				}
				keyList.Add(titleKey);
				
			}
			
			foreach (DataRow dr in dt.Rows)
			{
				ListViewItem lvi = new ListViewItem();
				lvi.SubItems.Clear();
				lvi.Text = dr[0].ToString();
				for(int index = 1; index < keyList.Count; index++)
				{
					string val = dr[keyList[index]].ToString();
					lvi.SubItems.Add(val);
				}
				lv.Items.Add(lvi);
			}
		}
	}
}
